from django import forms
from .models import Pillar, DeathCount


class PillarForm(forms.ModelForm):

    class Meta:
        model = Pillar
        fields = ("fb_id", "name", "categories", "importance", "short_description", "long_description", "context_url", "defection_url", "state", "defection_date", )

    def clean(self):
        cleaned_data = super(PillarForm, self).clean()
        state = cleaned_data.get("state")

        if state == "Defected":
            defection_date = cleaned_data.get("defection_date")
            if not defection_date: 
                raise forms.ValidationError("Defected pillars require a defection date")

        return cleaned_data


class DeathCountForm(forms.ModelForm):

    class Meta:
        model = DeathCount

class UploadFileForm(forms.Form):
    docfile = forms.FileField(label='CSV file to upload')
